//狼人
module.exports = function(room,chair) {
	var basic = require("./roleBasic.js")
	basic.call(this,chair)
	console.log(basic)
	this.name = "狼人"			//角色名
	this.role = "werewolf"		//角色类型
	this.camp = "werewolf"   	//阵营	werewolf  protoss  villager
	this.survive = true 	  	//存活状态
	this.votePower = true   	//投票权
	this.showRole = "normal"	//显示状态   
	//角色行动
	this.action = function(type,target,cb) {
		switch(type){
			case "kill":
				//刀人
				if(room.state != room.NIGHT_WEREWOLF_STATE){
					cb(false,"不在狼人阶段")
					return
				}
				var chair = this.chair
				if(this.role !== "werewolf"){
					cb(false,"身份错误：werewolf : "+this.role)
					return
				}
				if(!this.survive){
					cb(false,"已死亡")
					return
				}
				if(typeof(target) != "number" || !room.roleList[target].survive){
					cb(false,"目标错误 : "+target)
					return
				}
				if(room.killList[chair] !== undefined){
					cb(false,"已选择目标")
					return
				}
				room.killList[chair] = target
				var notify = {
					cmd : "werewolfChooseTarget",
					target : target,
					chair : chair
				}
				room.sendByRole("werewolf",notify)
				cb(true)
				//全部狼人已选择则提前结束
				var flag = true
				for(var i = 0;i < room.roleMap["werewolf"].length;i++){
					if(room.killList[i] != undefined){
						flag = false
						break
					}
				}
				if(flag){
					room.nextTime = (new Date()).getTime()
				}
			break
			case "boom":
				//自爆
				if(room.diurnal !=  "day"){
					cb(false,"不在白天阶段")
					return
				}
				//警上发言或者放逐发言时才可以自爆
				if(room.state !== room.DAY_RUNSHERIFF_SAY1 && room.state !== room.DAY_RUNSHERIFF_SAY2
					&& room.state !== room.DAY_PLAYER_SAY_1 && room.state !== room.DAY_PLAYER_SAY_2){
					cb(false,"状态错误 : "+this.role)
					return
				}
				var chair = this.chair
				if(this.role !== "werewolf"){
					cb(false,"身份错误：werewolf : "+this.role)
					return
				}
				if(!this.survive){
					cb(false,"已死亡")
					return
				}
				//清空函数栈   下一个函数为夜晚
				room.nextFun = []
				if(room.state == room.DAY_RUNSHERIFF_SAY1 || room.state == room.DAY_RUNSHERIFF_SAY2){
					room.sendAll({cmd : "sheriffDrain"})
				}
				room.nextFun.push(room.enterNight)
				//警上自爆时需先公布结果再进入夜晚
				if(room.state == room.DAY_RUNSHERIFF_SAY1 || room.state == room.DAY_RUNSHERIFF_SAY2){
					room.nextFun.unshift(room.announceResult)
				}
				room.dieDispose(chair,"boom")
				cb(true)
			break
			default :
				cb(false)
		}
	}
	//获取自身信息
	this.getRoleInfo = function() {
		var info = {
			name : this.name,
			role : this.role,
			camp : this.camp,
			survive : this.survive,
			votePower : this.votePower,
			showRole : this.showRole,
			werewolfs : room.roleMap["werewolf"],
			killList : room.killList
		}
		return info
	}
}